package shayu.search.controller;

import io.renren.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import shayu.search.service.MallSearchService;
import shayu.search.vo.SearchParm;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class SearchController {

    @Autowired
    private MallSearchService mallSearchService;

    /**
     *  自动将页面提交过来的所有请求查询参数封装成指定的对象
     * @param searchParm
     * @param model
     * @return
     */
    @GetMapping("/list.html")
    public String listPage(SearchParm searchParm, Model model, HttpServletRequest request){
        
        searchParm.set_queryString(request.getQueryString());
        // 1. 根据传递过来的页面的查询参数，去es中检索商品
        SearchParm search=mallSearchService.search(searchParm);

        model.addAttribute("result",search);
        return "list";
    }


}
